﻿@model thailandProject.Models.Pair<List<thailandProject.Models.EventEmail>, string>

@{
    ViewBag.Title = "Email";
}

<div id="Wrapper2">
    <div id="content_header">
        <div id="headerimage">
        </div>
        <div id="theheader">@ViewBag.Header</div> 
    </div>
    <!-- Left Column begins here -->
    <aside id="sidebar-wrapper">
        <nav class="sidebar">
            <h1>Compose Email</h1>
            <!-- CONTENT GOES HERE -->
            @using (Html.BeginForm("EventCompose", "Email", FormMethod.Post, new { id = "emailform" }))
            {
                int counter = 0;
                foreach(var mailData in Model.value1)
                {
                    string bodyID = "body_" + counter;
                    <div class="w100 floatleft">
                        <div class="floatleft" id="emailComposeToDiv">Email To <br /><input id="to" name="to" type="text" readonly="readonly" value="@mailData.client.clientEmail" /></div>
                        <div class="floatleft" id="emailComposeSubjectDiv">Subject <br /><input id="subject" name="subject" type="text" value="@mailData.subject" /></div>
                        <div class="floatleft w100">Body <br /><textarea name="@bodyID" id="@bodyID" style="width:95%; height:200px; border:1px solid #999999;">@mailData.message</textarea><span id="emailEasterEgg" style="visibility:hidden;">So... um... did you know the max length for this field is 524,000 characters?</span></div>
                        <input type="hidden" name="clientID" id="clientID" value="@mailData.client.clientID" />
                    </div>
                    if (counter < Model.value1.Count - 1)
                    {
                        <hr />
                    }
                }
                <input type="hidden" name="returnURL" value="@Model.value2" />
                <input type="hidden" name="donotsend" id="donotsend" value="false" />
                <span class="floatleft w60" style="margin-top:10px; margin-right:10px;"><img id="sendemail" src="../../images/sendemailicon.png" />
                    <img id="donotsendemail" src="../../images/button_do_not_send.png" /></span>
            }
        </nav>
        
        <!-- Left column ends here -->
    </aside>
    <!-- Right column begins here -->
    <article id="contents">
        
    </article>
    <!-- Right column ends here -->
</div>
<!-- Div wrapper2 ends here -->

<script>
    $("document").ready(function () {
        //alert("ready1");
        $("#sendemail").click(function () {
            $("#emailform").submit();
            //alert("end");
        })

        $("#donotsendemail").click(function () {
            if (confirm('Are you sure?\n\nThe data will still be saved, but the email will not be sent.')) {
                $("#donotsend").val('true');
                $("#emailform").submit();
            }
        })

        $("#body").keyup(function() {
            //The maximum length is set at 524,000 characters
            var message = $("#body").val();

            if (message.length > 524000) {
                message = message.substr(0, 524000);
                $("#body").val(message);
                $("#emailEasterEgg").attr('style', 'visibility:visible;');
            }
        })
    })
</script>